package classList;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class StudentTest {
    public static void main(String[] args) {
        List<Student> list = new ArrayList<Student>();

        list.add(new Student(1,"张三","女"));
        list.add(new Student(2,"李四","男"));
        list.add(new Student(3,"王五","女"));

        Student a = list.get(2);
        a.setCode(100);
        System.out.println(list.get(2));
        System.out.println("--------------------------");

        //得到指定人下标
        int index = list.indexOf(new Student(2,null,null));
        System.out.println(index);

        //移除指定下标人物
        list.remove(0);

        //移除指定对象
        list.remove(new Student(2,null,null));

        for (int i=0;i<list.size();i++){
            Student s = list.get(i);
            System.out.println(s);
        }
        System.out.println("----------");

        Iterator<Student> it = list.iterator();
        //判断集合有误下一个元素
        while (it.hasNext()){
            //取出下一个元素
            Student s = it.next();
            System.out.println(s);
        }
        System.out.println("----------");
        for (Student s:list){
            System.out.println(s);
        }
    }
}
